from src.core import *
from src.ui import *
from src.storage.file_manager import save_to_file,load_from_file

def main():
    '''main loop'''
    print("=== MY GAME CHARACTERS ===")
    items=load_from_file()
    while True:
        display_menu()
        choice=give_choice()
        if choice==1:
            name = input("Enter character name: ").strip()
            character_class = input("Enter character class: ").strip()
            try:
                level = int(input("Enter character level: "))
                if level < 1:
                    print("Level must be at least 1.")
                    continue
            except ValueError:
                print("Invalid level. Please enter a number.")
                continue
            items = create_item(items, name, character_class, level)
            save_to_file(items)

        elif choice == 2:   
            '''Display all'''
            display_item(items)
            
        elif choice == 3:  
            '''Delete character'''
            if not items:
                print("No characters to delete.")
                continue
                
            display_item(items)
            item_id = input("Enter character ID to delete: ")
            items = delete_item(items, item_id)
            save_to_file(items)
            
        elif choice == 4:   
            '''Quit'''
            print("Goodbye!")
            break
            
        else:
            print("Invalid choice. Please enter a number between 1-4.")

if __name__ == "__main__":
    
    main()